const fs = require('fs');
const path = require('path');
const child_process = require('child_process');

const HVIGOR_BOOSTRAP_JS_FILE = 'hvigor-bootstrap.js';
const HVIGOR_WRAPPER_PNPM_SCRIPT_FILE = 'pnpm-exec.js';
const HVIGOR_PNPM_CONFIG_FILE = 'hvigor-pnpm-config.json';

const HVIGOR_PROJECT_DEPENDENCY_PACKAGE_JSON_FILE = 'package.json';
const HVIGOR_PROJECT_DEPENDENCIES_HOME = 'hvigor';
const HVIGOR_PROJECT_WRAPPER_HOME = path.resolve(__dirname, '..');
const HVIGOR_PROJECT_ROOT_HOME = path.resolve(HVIGOR_PROJECT_WRAPPER_HOME, '..');

const HVIGOR_PNPM_CONFIG_FILE_PATH = path.resolve(__dirname, HVIGOR_PNPM_CONFIG_FILE);
const HVIGOR_PROJECT_DEPENDENCY_PACKAGE_JSON_FILE_PATH = path.resolve(HVIGOR_PROJECT_DEPENDENCIES_HOME, HVIGOR_PROJECT_DEPENDENCY_PACKAGE_JSON_FILE);
const HVIGOR_BOOSTRAP_JS_FILE_PATH = path.resolve(__dirname, HVIGOR_BOOSTRAP_JS_FILE);
const HVIGOR_WRAPPER_PNPM_SCRIPT_FILE_PATH = path.resolve(__dirname, HVIGOR_WRAPPER_PNPM_SCRIPT_FILE);

// Execute hvigor-bootstrap.js
if (fs.existsSync(HVIGOR_BOOSTRAP_JS_FILE_PATH)) {
    require(HVIGOR_BOOSTRAP_JS_FILE_PATH);
} else {
    throw Error(`Error: ${HVIGOR_BOOSTRAP_JS_FILE} is not exist.`);
}
